<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
  <meta name="referrer" content="never">
  <title>JS动画</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      list-style: none;
    }

    .box{
      position: absolute;
      top: 50px;
      left: 50px;
      width: 150px;
      height: 150px;
      background-color: #f00;
    }
  </style>
</head>
<body>
  JS动画：
    闪现动画

  <div class="box"></div>

  <script type="text/javascript">
    var box = document.querySelector(".box");  

    // 余涛：设置变量 = 次数  奇数次->600 偶数回来
    // var count = 0;
    var flag = true; // 默认起始位置是 true
    box.onclick = function (){
      // count ++;
      // flag = !flag;

      // if(count % 2 === 0){
      //   this.style.left = "50px";
      // }else {
      //   this.style.left = "600px";
      // }

      // 简化 =>
      // count % 2 === 0 ? this.style.left = "50px" : this.style.left = "600px";

      // 简化 =>
      // this.style.left = count % 2 === 0 ? "50px" : "600px";

      // 简化 =>
      // this.style.left = count % 2 ? "600px" : "50px";

      // 简化 =>
      // this.style.left = flag ? "50px" : "600px";

      // 简化 =>  小括号可以获取赋值语句的赋值结果
      this.style.left = (flag = !flag) ? "50px" : "600px";
    }
  </script>
</body>
</html>